/*
 * Author: Alberto De Pena
 * Applied Algorithms
 * led.cpp
*/
#include <iostream>
#include <fstream>
#include <bitset>
using namespace std;

void main()
{
    ifstream fin;
    ofstream fout;

	fin.open( "led.in" );
    fout.open( "led.out" );

    int number, i, j;
    unsigned int ledArray[10];
    bool printLed[10];

    fin >> number;
    while( number > 0 )
    { 
        bitset<7> bitZero  ( string( "1110111" ) );
        bitset<7> bitOne   ( string( "0100100" ) );
        bitset<7> bitTwo   ( string( "1011101" ) );
        bitset<7> bitThree ( string( "1101101" ) );
        bitset<7> bitFour  ( string( "0101110" ) );
        bitset<7> bitFive  ( string( "1101011" ) );
        bitset<7> bitSix   ( string( "1111011" ) );
        bitset<7> bitSeven ( string( "0100101" ) );
        bitset<7> bitEight ( string( "1111111" ) );
        bitset<7> bitNine  ( string( "0101111" ) );


        for( i = 0; i < 10; i++ )
            printLed[i] = false;

        bool once = true;
        fout << "Case <" << number;

        do
        {
            if( once )
                once = false;
            else
                fout << "," << number;

            bitZero.reset( number - 1 );
            bitOne.reset( number - 1 );
            bitTwo.reset( number - 1 );
            bitThree.reset( number - 1 );
            bitFour.reset( number - 1 );
            bitFive.reset( number - 1 );
            bitSix.reset( number - 1 );
            bitSeven.reset( number - 1 );
            bitEight.reset( number - 1 );
            bitNine.reset( number - 1 );

            fin >> number;
        } 
		while( number > 0 );
        
        fout << ">:";

        ledArray[0] = bitZero.to_ulong();
        ledArray[1] = bitOne.to_ulong();
        ledArray[2] = bitTwo.to_ulong();
        ledArray[3] = bitThree.to_ulong();
        ledArray[4] = bitFour.to_ulong();
        ledArray[5] = bitFive.to_ulong();
        ledArray[6] = bitSix.to_ulong();
        ledArray[7] = bitSeven.to_ulong();
        ledArray[8] = bitEight.to_ulong();
        ledArray[9] = bitNine.to_ulong();

        for( i = 0; i < 10; i++ )
        {
            bool same = false;
            for( j = i + 1; j < 10; j++ )
            {
                if( ledArray[i] == ledArray[j] )
                {
                    if( !same && !printLed[i] )
                    {
                        fout << " {" << i << "," << j;
                        printLed[i] = true;
                        printLed[j] = true;
                        same = true;
                    }
                    else if( !printLed[j] )
                    {
                        fout << "," << j;
                        printLed[j] = true;
                    }
                }
            }
            if( same )
                fout << "}";
        }
        fout << endl;

        fin >> number;
    }
    fin.close();
    fout.close();
}

